#include "dialog_configworkgroupparas.h"
#include "ui_dialog_configworkgroupparas.h"
#include <QDebug>
#include "messageboxutil.h"
#include "dialog_camadjust.h"
#include "dialog_lightcontrol.h"
#include "LineEditProductClass.h"
#include "dialog_newaddgroup.h"

Dialog_configWorkGroupParas::Dialog_configWorkGroupParas(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog_configWorkGroupParas)
{
    ui->setupUi(this);

    m_iniManager = new iniManager("./config/workGroupConfig.ini");

//    ui->lineEdit_productClass_set->setStyleSheet("color:black");
    ui->productClassWidget->setStyleSheet("color:black");
    ui->lineEdit_workGroupId_set->setStyleSheet("color:black");

    ui->lineEdit_productClass->setStyleSheet("color:black");
    ui->LineEdit_size->setStyleSheet("color:black");

    // QSpinBox设置为当前滑动条值  顶部调焦
    ui->hSlider_topCameraFoucs->setValue(ui->spinBox_topCameraFoucs->value());
    // 连接信号和槽
    connect(ui->hSlider_topCameraFoucs, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_topCameraFoucs->setValue(value);
    });
    connect(ui->spinBox_topCameraFoucs, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_topCameraFoucs, &QSlider::setValue);

    // 连接信号和槽
    connect(ui->hSlider_topCameraFoucs, &QSlider::valueChanged, this, [=


            ](int value) {
        ui->spinBox_topCameraFoucs->setValue(value);
    });
    connect(ui->spinBox_topCameraFoucs, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_topCameraFoucs, &QSlider::setValue);


    // QSpinBox设置为当前滑动条值  顶部光源
    ui->hSlider_topCameraLightValue->setValue(ui->spinBox_topCameraLightValue->value());
    // 连接信号和槽
    connect(ui->hSlider_topCameraLightValue, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_topCameraLightValue->setValue(value);
    });
    connect(ui->spinBox_topCameraLightValue, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_topCameraLightValue, &QSlider::setValue);

    // 连接信号和槽
    connect(ui->hSlider_topCameraLightValue, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_topCameraLightValue->setValue(value);
    });
    connect(ui->spinBox_topCameraLightValue, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_topCameraLightValue, &QSlider::setValue);


    // QSpinBox设置为当前滑动条值 侧面调焦 A
    ui->hSlider_sideCameraFoucsA->setValue(ui->spinBox_sideCameraFoucsA->value());
    // 连接信号和槽
    connect(ui->hSlider_sideCameraFoucsA, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideCameraFoucsA->setValue(value);
    });
    connect(ui->spinBox_sideCameraFoucsA, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideCameraFoucsA, &QSlider::setValue);

    // 连接信号和槽
    connect(ui->hSlider_sideCameraFoucsA, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideCameraFoucsA->setValue(value);
    });
    connect(ui->spinBox_sideCameraFoucsA, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideCameraFoucsA, &QSlider::setValue);



    // QSpinBox设置为当前滑动条值  侧面光源 A
    ui->hSlider_sideCameraLightA->setValue(ui->spinBox_sideCameraLightA->value());
    // 连接信号和槽
    connect(ui->hSlider_sideCameraLightA, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideCameraLightA->setValue(value);
    });
    connect(ui->spinBox_sideCameraLightA, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideCameraLightA, &QSlider::setValue);

    // 连接信号和槽
    connect(ui->hSlider_sideCameraLightA, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideCameraLightA->setValue(value);
    });
    connect(ui->spinBox_sideCameraLightA, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideCameraLightA, &QSlider::setValue);



    // QSpinBox设置为当前滑动条值
    ui->hSlider_sideFillLightA->setValue(ui->spinBox_sideFillLightA->value());
    // 连接信号和槽
    connect(ui->hSlider_sideFillLightA, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideFillLightA->setValue(value);
    });
    connect(ui->spinBox_sideFillLightA, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideFillLightA, &QSlider::setValue);

    // 连接信号和槽
    connect(ui->hSlider_sideFillLightA, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideFillLightA->setValue(value);
    });
    connect(ui->spinBox_sideFillLightA, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideFillLightA, &QSlider::setValue);





    // QSpinBox设置为当前滑动条值 侧面调焦 B
    ui->hSlider_sideCameraFoucsB->setValue(ui->spinBox_sideCameraFoucsB->value());
    // 连接信号和槽
    connect(ui->hSlider_sideCameraFoucsB, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideCameraFoucsB->setValue(value);
    });
    connect(ui->spinBox_sideCameraFoucsB, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideCameraFoucsB, &QSlider::setValue);

    // 连接信号和槽
    connect(ui->hSlider_sideCameraFoucsB, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideCameraFoucsB->setValue(value);
    });
    connect(ui->spinBox_sideCameraFoucsB, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideCameraFoucsB, &QSlider::setValue);



    // QSpinBox设置为当前滑动条值  侧面光源 B
    ui->hSlider_sideCameraLightB->setValue(ui->spinBox_sideCameraLightB->value());
    // 连接信号和槽
    connect(ui->hSlider_sideCameraLightB, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideCameraLightB->setValue(value);
    });
    connect(ui->spinBox_sideCameraLightB, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideCameraLightB, &QSlider::setValue);

    // 连接信号和槽
    connect(ui->hSlider_sideCameraLightB, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideCameraLightB->setValue(value);
    });
    connect(ui->spinBox_sideCameraLightB, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideCameraLightB, &QSlider::setValue);



    // QSpinBox设置为当前滑动条值
    ui->hSlider_sideFillLightB->setValue(ui->spinBox_sideFillLightB->value());
    // 连接信号和槽
    connect(ui->hSlider_sideFillLightB, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideFillLightB->setValue(value);
    });
    connect(ui->spinBox_sideFillLightB, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideFillLightB, &QSlider::setValue);

    // 连接信号和槽
    connect(ui->hSlider_sideFillLightB, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideFillLightB->setValue(value);
    });
    connect(ui->spinBox_sideFillLightB, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideFillLightB, &QSlider::setValue);





    // QSpinBox设置为当前滑动条值 侧面调焦 C
    ui->hSlider_sideCameraFoucsC->setValue(ui->spinBox_sideCameraFoucsC->value());
    // 连接信号和槽
    connect(ui->hSlider_sideCameraFoucsC, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideCameraFoucsC->setValue(value);
    });
    connect(ui->spinBox_sideCameraFoucsC, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideCameraFoucsC, &QSlider::setValue);

    // 连接信号和槽
    connect(ui->hSlider_sideCameraFoucsC, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideCameraFoucsC->setValue(value);
    });
    connect(ui->spinBox_sideCameraFoucsC, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideCameraFoucsC, &QSlider::setValue);


    // QSpinBox设置为当前滑动条值  侧面光源 C
    ui->hSlider_sideCameraLightC->setValue(ui->spinBox_sideCameraLightC->value());
    // 连接信号和槽
    connect(ui->hSlider_sideCameraLightC, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideCameraLightC->setValue(value);
    });
    connect(ui->spinBox_sideCameraLightC, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideCameraLightC, &QSlider::setValue);

    // 连接信号和槽
    connect(ui->hSlider_sideCameraLightC, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideCameraLightC->setValue(value);
    });
    connect(ui->spinBox_sideCameraLightC, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideCameraLightC, &QSlider::setValue);


    // QSpinBox设置为当前滑动条值
    ui->hSlider_sideFillLightC->setValue(ui->spinBox_sideFillLightC->value());
    // 连接信号和槽
    connect(ui->hSlider_sideFillLightC, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideFillLightC->setValue(value);
    });
    connect(ui->spinBox_sideFillLightC, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideFillLightC, &QSlider::setValue);

    // 连接信号和槽
    connect(ui->hSlider_sideFillLightC, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideFillLightC->setValue(value);
    });
    connect(ui->spinBox_sideFillLightC, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideFillLightC, &QSlider::setValue);



    // QSpinBox设置为当前滑动条值 侧面调焦 D
    ui->hSlider_sideCameraFoucsD->setValue(ui->spinBox_sideCameraFoucsD->value());
    // 连接信号和槽
    connect(ui->hSlider_sideCameraFoucsD, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideCameraFoucsD->setValue(value);
    });
    connect(ui->spinBox_sideCameraFoucsD, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideCameraFoucsD, &QSlider::setValue);

    // 连接信号和槽
    connect(ui->hSlider_sideCameraFoucsD, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideCameraFoucsD->setValue(value);
    });
    connect(ui->spinBox_sideCameraFoucsD, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideCameraFoucsD, &QSlider::setValue);



    // QSpinBox设置为当前滑动条值  侧面光源 D
    ui->hSlider_sideCameraLightD->setValue(ui->spinBox_sideCameraLightD->value());
    // 连接信号和槽
    connect(ui->hSlider_sideCameraLightD, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideCameraLightD->setValue(value);
    });
    connect(ui->spinBox_sideCameraLightD, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideCameraLightD, &QSlider::setValue);

    // 连接信号和槽
    connect(ui->hSlider_sideCameraLightD, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideCameraLightD->setValue(value);
    });
    connect(ui->spinBox_sideCameraLightD, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideCameraLightD, &QSlider::setValue);


    // QSpinBox设置为当前滑动条值
    ui->hSlider_sideFillLightD->setValue(ui->spinBox_sideFillLightD->value());
    // 连接信号和槽
    connect(ui->hSlider_sideFillLightD, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideFillLightD->setValue(value);
    });
    connect(ui->spinBox_sideFillLightD, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideFillLightD, &QSlider::setValue);

    // 连接信号和槽
    connect(ui->hSlider_sideFillLightD, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_sideFillLightD->setValue(value);
    });
    connect(ui->spinBox_sideFillLightD, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_sideFillLightD, &QSlider::setValue);


    // QSpinBox设置为当前滑动条值
    ui->hSlider_bottomCameraLightValue->setValue(ui->spinBox_bottomCameraLightValueOf2->value());
    // 连接信号和槽
    connect(ui->hSlider_bottomCameraLightValue, &QSlider::valueChanged, this, [=](int value) {
        ui->spinBox_bottomCameraLightValueOf2->setValue(value);
    });
    connect(ui->spinBox_bottomCameraLightValueOf2, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
             ui->hSlider_bottomCameraLightValue, &QSlider::setValue);


    QRegExp regExp("^\\d+\\*\\d+\\*\\d+$"); // 正则表达式，匹配形如"L*H*G"的格式
    QValidator *validator = new QRegExpValidator(regExp, this);
    ui->LineEdit_size->setValidator(validator);
    // 连接槽
    connect(ui->LineEdit_size, &QLineEdit::textChanged, [=](QString str){

        if(str.isEmpty()){

            return;
        }

        QStringList str_list = str.split("*");

        if(str_list.size() != 3)
        {
            return;
        }

        uint16_t l = str_list.at(0).toUInt();
        uint16_t w = str_list.at(1).toUInt();
        uint16_t h = str_list.at(2).toUInt();

        if(l < 450 || w < 450)
        {
            ui->comboBox_chainWidth->setCurrentText("窄");
        } else {
            ui->comboBox_chainWidth->setCurrentText("宽");
        }
    });


//    QIntValidator *validator_L = new QIntValidator(0, 1000, ui->lineEdit_L_set);
//    ui->lineEdit_L_set->setValidator(validator_L);

//    QIntValidator *validator_W = new QIntValidator(0, 1000, ui->lineEdit_W_set);
//    ui->lineEdit_W_set->setValidator(validator_W);

//    QIntValidator *validator_H = new QIntValidator(0, 1000, ui->lineEdit_H_set);
//    ui->lineEdit_H_set->setValidator(validator_H);

    initData();

//    connect(ui->lineEdit_L_set, &QLineEdit::editingFinished, this, &Dialog_configWorkGroupParas::do_LWH_To_currGroupId);
//    connect(ui->lineEdit_W_set, &QLineEdit::editingFinished, this, &Dialog_configWorkGroupParas::do_LWH_To_currGroupId);
//    connect(ui->lineEdit_H_set, &QLineEdit::editingFinished, this, &Dialog_configWorkGroupParas::do_LWH_To_currGroupId);
    connect(ui->productSizeWidget, &LineEditLWH::sizeChange, this, &Dialog_configWorkGroupParas::do_LWH_To_currGroupId);


    connect(ui->comboBox_chainWidth_set, &QComboBox::currentTextChanged, [=](QString text){
        QStringList groupIdList = iniManager::splitString(ui->lineEdit_workGroupId_set->text());

        if(!groupIdList.isEmpty())
        {
            QStringList groupId;

            groupId << groupIdList.at(0) << groupIdList.at(1) << groupIdList.at(2) << groupIdList.at(3) << iniManager::getGroupType(text);

            ui->lineEdit_workGroupId_set->setText(groupId.join("_"));
        }
    });

    int max = ui->hSlider_sideFillLightA->maximum();

    ui->hSlider_topCameraLightValue->setValue(max);
    ui->hSlider_bottomCameraLightValue->setValue(max);

    ui->hSlider_sideCameraLightA->setValue(max);
    ui->hSlider_sideCameraLightB->setValue(max);
    ui->hSlider_sideCameraLightC->setValue(max);
    ui->hSlider_sideCameraLightD->setValue(max);

    ui->hSlider_sideFillLightA->setValue(max);
    ui->hSlider_sideFillLightB->setValue(max);
    ui->hSlider_sideFillLightC->setValue(max);
    ui->hSlider_sideFillLightD->setValue(max);

    ui->stackedWidget->setCurrentIndex(0);
}


void Dialog_configWorkGroupParas::do_LWH_To_currGroupId()
{
    QStringList sizeList = ui->productSizeWidget->getSize().split("*");

    QString l = sizeList.at(0);
    QString w = sizeList.at(1);
    QString h = sizeList.at(2);

    QString name, type;

//    if(!l.isEmpty())
//    {
//        uint16_t u16_l = l.toUInt();
//        if(u16_l == 220 || u16_l == 450)
//        {

//        } else {
//            ui->lineEdit_L_set->clear();
//            return;
//        }
//    }

//    if(!w.isEmpty())
//    {
//        uint16_t u16_w = w.toUInt();
//        if(u16_w == 220 || u16_w == 450)
//        {

//        } else {
//            ui->lineEdit_W_set->clear();
//            return;
//        }
//    }


//    if(!h.isEmpty())
//    {
//        uint16_t u16_h = h.toUInt();
//        if(u16_h == 220 || u16_h == 450)
//        {

//        } else {
//            ui->lineEdit_H_set->clear();
//            return;
//        }
//    }


    if(m_newGroupFlag)
    {
        m_Id_set = m_iniManager->readValue("current", "count").toString();

        if(!l.isEmpty() && !w.isEmpty())
        {
            if(l.toUInt() < 450 || w.toUInt() < 450){
                type = "Z";
            } else {
                type = "K";
            }
        }

        name = QString("%1_%2_%3_%4_%5").arg(m_Id_set).arg(l).arg(w).arg(h).arg(type);

    } else {
        QString currGroup = ui->lineEdit_workGroupId_set->text().trimmed();
        QStringList currentGroupIdList = iniManager::splitString(currGroup);
        if(currentGroupIdList.isEmpty())
        {
            qDebug() << "工作组编号，拆分错误";
            MessageBoxUtil::hintMessage(this, MessageBoxUtil::Warning, "警告", QString("初始化：工作组：%1 格式不正确!").arg(currentGroup));

            return;
        }

        type = iniManager::getGroupType(iniManager::getGroupType(w.toUInt(), l.toUInt()));

        uint16_t Id = QString(currGroup.at(0)).toUInt();
        name = iniManager::getGroupIdQString(Id, l.toUInt(), w.toUInt(), h.toUInt(), type);
    }

    ui->comboBox_chainWidth_set->setCurrentText(iniManager::getGroupType(type));
    ui->lineEdit_workGroupId_set->setText(name);


}

Dialog_configWorkGroupParas::~Dialog_configWorkGroupParas()
{
    delete ui;
    if(settings != nullptr)
        delete settings;
    if(m_iniManager != nullptr)
        delete m_iniManager;
}

void Dialog_configWorkGroupParas::setGroupId_To_size_type(QString str)
{
    if(str.isEmpty()){

        return;
    }

    QStringList str_list = str.split("*");

    if(str_list.size() != 3)
    {
        return;
    }

//    ui->lineEdit_L_set->setText(str_list.at(0));
//    ui->lineEdit_W_set->setText(str_list.at(1));
//    ui->lineEdit_H_set->setText(str_list.at(2));

    ui->productSizeWidget->setSize(str);

    uint16_t l = str_list.at(0).toUInt();
    uint16_t w = str_list.at(1).toUInt();
//    uint16_t h = str_list.at(2).toUInt();

    if(l < 450 || w < 450)
    {
        ui->comboBox_chainWidth_set->setCurrentText("窄");
    } else {
        ui->comboBox_chainWidth_set->setCurrentText("宽");
    }
}



void Dialog_configWorkGroupParas::initData()
{
    // 获取所有的组
    groups = m_iniManager->allGroups();
    groups.removeOne("current");
    groups.removeOne("other");
    groups.removeOne("template");


    if (groups.isEmpty()) {
        qDebug() << "No groups found in the INI file.";
    } else {
        // 初始化当前组索引
        currentGroupIndex = m_iniManager->readValue("current", "group").toInt();

        if(currentGroupIndex >= groups.size())
        {
            currentGroupIndex = 0; // 到第一个组
            m_iniManager->writeValue("current","group", currentGroupIndex);
        }

        ui->comboBox_workGroupId->clear();
        for(const QString &group : groups)
        {
            QString name = m_iniManager->readValue(group, "name").toString();
            ui->comboBox_workGroupId->addItem(name);
        }

        currentGroup = m_iniManager->readValue(QString::number(currentGroupIndex), "name").toString();
        qDebug() << "Current group:" << currentGroup;

        ui->comboBox_workGroupId->setCurrentText(currentGroup);

        // 设置组上限索引
        maxGroupIndex = groups.size() - 1;
        m_iniManager->writeValue("current", "count", groups.size());

        QStringList currentGroupIdList = iniManager::splitString(currentGroup);
        if(currentGroupIdList.isEmpty())
        {
            qDebug() << "工作组编号，拆分错误";
            MessageBoxUtil::hintMessage(this, MessageBoxUtil::Warning, "警告", QString("初始化：工作组：%1 格式不正确!").arg(currentGroup));

            return;
        }

        ui->stackedWidget->setCurrentIndex(0);
        QString currGroupId = currentGroupIdList.at(0);

        do_setCurrentGroupBrowse(currGroupId);

    }
}


// 保存到配置文件
bool Dialog_configWorkGroupParas::savePara()
{
//    QString name  = ui->LineEdit_workGroupName->text();

    // 获取当前工作组编号
    QString name  = ui->lineEdit_workGroupId_set->text();


//    QString l = ui->lineEdit_L_set->text();
//    QString w = ui->lineEdit_W_set->text();
//    QString h = ui->lineEdit_H_set->text();
//    QString size = QString("%1*%2*%3").arg(l).arg(w).arg(h);
    QString size = ui->productSizeWidget->getSize();


    QStringList currentGroupIdList = iniManager::splitString(name);
    if(currentGroupIdList.isEmpty())
    {
        qDebug() << "工作组编号，拆分错误";
        MessageBoxUtil::hintMessage(this, MessageBoxUtil::Warning, "警告", QString("savePara 保存:\n工作组：%1 格式不正确!").arg(name));

        return false;
    }

    int topCamFocusVal      = ui->hSlider_topCameraFoucs->value();
    int topLightVale        = ui->hSlider_topCameraLightValue->value();
    int sideCamFocusVal_A   = ui->hSlider_sideCameraFoucsA->value();
    int sideCamLight_A      = ui->hSlider_sideCameraLightA->value();
    int sideFillLightA      = ui->hSlider_sideFillLightA->value();

    int sideCamFocusVal_B   = ui->hSlider_sideCameraFoucsB->value();
    int sideCamLight_B      = ui->hSlider_sideCameraLightB->value();
    int sideFillLightB      = ui->hSlider_sideFillLightB->value();

    int sideCamFocusVal_C   = ui->hSlider_sideCameraFoucsC->value();
    int sideCamLight_C      = ui->hSlider_sideCameraLightC->value();
    int sideFillLightC      = ui->hSlider_sideFillLightC->value();

    int sideCamFocusVal_D   = ui->hSlider_sideCameraFoucsD->value();
    int sideCamLight_D      = ui->hSlider_sideCameraLightD->value();
    int sideFillLightD      = ui->hSlider_sideFillLightD->value();
//    int sideLightVal        = ui->hSlider_sideCameraLightValue->value();
//    int sideFillLightVal    = ui->hSlider_sideCameraFillLight->value();
    int bottomLightVal      = ui->hSlider_bottomCameraLightValue->value();

    QString currGroupId = currentGroupIdList.at(0);

    QString type = iniManager::getGroupType(ui->comboBox_chainWidth->currentText());

//    QString materialNo = ui->lineEdit_materialNo_set->text().trimmed();
//    QString workProcedureSequence = ui->lineEdit_workProcedureSequence_set->text().trimmed();

//    QString productClass = QString("%1_%2").arg(materialNo).arg(workProcedureSequence);
    QString productClass = ui->productClassWidget->getProductClass();

//    QString productClass =
    QVariantMap saveGroupMap;

    saveGroupMap.insert("name", name);
    saveGroupMap.insert("size", size);
    saveGroupMap.insert("type", type);
    saveGroupMap.insert("productClass", productClass);
    saveGroupMap.insert("topCamFocusVal", topCamFocusVal);
    saveGroupMap.insert("topLightVale", topLightVale);
    saveGroupMap.insert("sideCamFocusVal_A", sideCamFocusVal_A);
    saveGroupMap.insert("sideCamLightVal_A", sideCamLight_A);
    saveGroupMap.insert("sideFillLightVal_A", sideFillLightA);

    saveGroupMap.insert("sideCamFocusVal_B", sideCamFocusVal_B);
    saveGroupMap.insert("sideCamLightVal_B", sideCamLight_B);
    saveGroupMap.insert("sideFillLightVal_B", sideFillLightB);

    saveGroupMap.insert("sideCamFocusVal_C", sideCamFocusVal_C);
    saveGroupMap.insert("sideCamLightVal_C", sideCamLight_C);
    saveGroupMap.insert("sideFillLightVal_C", sideFillLightC);

    saveGroupMap.insert("sideCamFocusVal_D", sideCamFocusVal_D);
    saveGroupMap.insert("sideCamLightVal_D", sideCamLight_D);
    saveGroupMap.insert("sideFillLightVal_D", sideFillLightD);
//    saveGroupMap.insert("sideLightVal", sideLightVal);
//    saveGroupMap.insert("sideFillLightVal", sideFillLightVal);
    saveGroupMap.insert("bottomLightVal", bottomLightVal);

    if(m_iniManager->addGroup(currGroupId, saveGroupMap))
    {
        m_iniManager->writeValue("current","group", currGroupId);

        return true;
    }
    return false;
}
void Dialog_configWorkGroupParas::loatPara()
{

}

void Dialog_configWorkGroupParas::on_btn_save_clicked()
{
    // 获取当前工作组编号
    QString name = ui->lineEdit_workGroupId_set->text().trimmed();


    QStringList SizeList = ui->productSizeWidget->getSize().split("*");

    QString L = SizeList.at(0);
    QString W = SizeList.at(1);
    QString H = SizeList.at(2);

    QStringList productClassList = ui->productClassWidget->getProductClass().split("_");

    if(productClassList.size() != 2)
    {

        MessageBoxUtil::hintMessage(this, MessageBoxUtil::Information, "警告", QString("物料编号_工序编号 不能空!"));
        return;
    }

    QString materialNo = productClassList.at(0);
    QString workProcedureSequence = productClassList.at(1);
    QString productClass = ui->productClassWidget->getProductClass();

    // 物料编号
    if(materialNo.isEmpty())
    {
        MessageBoxUtil::hintMessage(this, MessageBoxUtil::Information, "警告", QString("物料编号不能空!"));

        return;
    }

    // 工序编号
    if(workProcedureSequence.isEmpty())
    {
        MessageBoxUtil::showMessage(this, MessageBoxUtil::Information, "警告", QString("工序编号不能空!"));

        return;
    }

    // 长
    if(L.isEmpty())
    {
        if(QMessageBox::Yes == MessageBoxUtil::hintMessage(this, MessageBoxUtil::Information, "警告", QString("长度不能空!")))

        return;
    }

    // 宽
    if(W.isEmpty())
    {
        MessageBoxUtil::hintMessage(this, MessageBoxUtil::Information, "警告", QString("宽度不能空!"));

        return;
    }

    // 高
    if(H.isEmpty())
    {
        MessageBoxUtil::hintMessage(this, MessageBoxUtil::Information, "警告", QString("高度不能空!"));

        return;
    }


    // 拆解编号，检查工作组编号格式
    QStringList groupIdList = iniManager::splitString(name);

    if(groupIdList.isEmpty())
    {
        qDebug() << "工作组编号，拆分错误";
        MessageBoxUtil::hintMessage(this, MessageBoxUtil::Warning, "警告", QString("保存 \n工作组：%1 格式不正确!").arg(name));

        return;
    }

    // 检查产品类型是否已经绑定
    // 匹配工作组
//    QString csvGroup = m_iniManager->getGroup("productClass", productClass);
//    if(!csvGroup.isEmpty())
//    {
//        // 已存在，绑定
//        MessageBoxUtil::hintMessage(this, MessageBoxUtil::Information, "警告", QString("产品类别：%1\n已绑定配方：%2").arg(productClass).arg(csvGroup));

//        qDebug() << QString("产品类别：%1 \t 已经绑定：%2").arg(productClass).arg(csvGroup);

//        return;
//    }

    if(savePara())
    {
        // 弹窗提示，保存成功
        MessageBoxUtil::hintMessage(this, MessageBoxUtil::Information, "提示", QString("保存成功!"));

        // 拆解编号，检查工作组编号格式
        QStringList currGroupId = iniManager::splitString(ui->lineEdit_workGroupId_set->text());
        if(currGroupId.isEmpty())
        {
            qDebug() << "工作组编号，拆分错误";
            MessageBoxUtil::hintMessage(this, MessageBoxUtil::Warning, "警告", QString("保存 显示:\n工作组：%1 格式不正确!").arg(ui->lineEdit_workGroupId_set->text()));
        }

        // 清除产品尺寸
        ui->productSizeWidget->clear();

        initData();
        ui->stackedWidget->setCurrentIndex(0);
    } else {
        MessageBoxUtil::hintMessage(this, MessageBoxUtil::Critical, "提示", QString("保存失败!"));

    }
}


void Dialog_configWorkGroupParas::on_btn_cancel_clicked()
{
    // 初始化，清空
//    ui->lineEdit_L_set->clear();    // 长
//    ui->lineEdit_W_set->clear();    // 宽
//    ui->lineEdit_H_set->clear();    // 高
    ui->productSizeWidget->clear(); // 产品尺寸

//    ui->lineEdit_productClass_set->clear(); // 产品类别
    ui->productClassWidget->clear();
    ui->lineEdit_workGroupId_set->clear();  // 工作组编号
    ui->stackedWidget->setCurrentIndex(0);
}

void Dialog_configWorkGroupParas::do_setCurrentGroupShow(const QString &group)
{
//    ui->lineEdit_workGroupId_set->setText(m_iniManager->readValue(group,"name").toString());
    ui->lineEdit_workGroupId_set->setText(ui->comboBox_workGroupId->currentText());
//    ui->LineEdit_workGroupName->setText(m_iniManager->readValue(group,"name").toString());
//    ui->LineEdit_size->setText(m_iniManager->readValue(group,"size").toString());

    setGroupId_To_size_type(m_iniManager->readValue(group,"size").toString());


    // QStringList currGroupId = iniManager::splitString(ui->LineEdit_workGroupName->text());
    QStringList currGroupId = iniManager::splitString(ui->comboBox_workGroupId->currentText());
    if(currGroupId.isEmpty())
    {
        qDebug() << "工作组编号，拆分错误";
//        if(MessageBoxUtil::Ok == MessageBoxUtil::showMessage(this, MessageBoxUtil::Warning, "警告", QString("Show 显示:\n工作组：%1 格式不正确!").arg(group), MessageBoxUtil::Ok))
        {

        }
        return;
    } else {
//        ui->comboBox_chainWidth->setCurrentText(iniManager::getGroupType(currGroupId.at(1).toUInt()));
    }




//    ui->comboBox_chainWidth->setCurrentText(m_iniManager->readValue(currentGroup, "type").toString());
    ui->comboBox_chainWidth->setCurrentText(iniManager::getGroupType(currGroupId.at(1).toUInt(), currGroupId.at(2).toUInt()));

//    ui->lineEdit_productClass_set->setText(m_iniManager->readValue(group, "productClass").toString());
    ui->productClassWidget->setProductClass(m_iniManager->readValue(group, "productClass").toString());

    ui->hSlider_topCameraFoucs->setValue(m_iniManager->readValue(group,"topCamFocusVal").toInt());
    ui->hSlider_topCameraLightValue->setValue(m_iniManager->readValue(group,"topLightVale").toInt());

    ui->hSlider_sideCameraFoucsA->setValue(m_iniManager->readValue(group,"sideCamFocusVal_A").toInt());
    ui->hSlider_sideCameraLightA->setValue(m_iniManager->readValue(group,"sideCamLightVal_A").toInt());
    ui->hSlider_sideFillLightA->setValue(m_iniManager->readValue(group,"sideFillLightVal_A").toInt());

    ui->hSlider_sideCameraFoucsB->setValue(m_iniManager->readValue(group,"sideCamFocusVal_B").toInt());
    ui->hSlider_sideCameraLightB->setValue(m_iniManager->readValue(group,"sideCamLightVal_B").toInt());
    ui->hSlider_sideFillLightB->setValue(m_iniManager->readValue(group,"sideFillLightVal_B").toInt());

    ui->hSlider_sideCameraFoucsC->setValue(m_iniManager->readValue(group,"sideCamFocusVal_C").toInt());
    ui->hSlider_sideCameraLightC->setValue(m_iniManager->readValue(group,"sideCamLightVal_C").toInt());
    ui->hSlider_sideFillLightC->setValue(m_iniManager->readValue(group,"sideFillLightVal_C").toInt());

    ui->hSlider_sideCameraFoucsD->setValue(m_iniManager->readValue(group,"sideCamFocusVal_D").toInt());
    ui->hSlider_sideCameraLightD->setValue(m_iniManager->readValue(group,"sideCamLightVal_D").toInt());
    ui->hSlider_sideFillLightD->setValue(m_iniManager->readValue(group,"sideFillLightVal_D").toInt());
//    ui->hSlider_sideCameraLightValue->setValue(m_iniManager->readValue(group,"sideLightVal").toInt());
//    ui->hSlider_sideCameraFillLight->setValue(m_iniManager->readValue(group,"sideFillLightVal").toInt());

    ui->hSlider_bottomCameraLightValue->setValue(m_iniManager->readValue(group,"bottomLightVal").toInt());

//    m_iniManager->writeValue("current","group", currGroupId.at(0));
}



void Dialog_configWorkGroupParas::do_setCurrentGroupBrowse(const QString &group)
{
    ui->comboBox_workGroupId->setCurrentText(m_iniManager->readValue(group,"name").toString());

//    ui->LineEdit_workGroupName->setText(m_iniManager->readValue(group,"name").toString());
    ui->LineEdit_size->setText(m_iniManager->readValue(group,"size").toString());


    // QStringList currGroupId = iniManager::splitString(ui->LineEdit_workGroupName->text());
    QStringList currGroupId = iniManager::splitString(ui->comboBox_workGroupId->currentText());
    if(currGroupId.isEmpty())
    {
        qDebug() << "工作组编号，拆分错误";
//        if(MessageBoxUtil::Ok == MessageBoxUtil::showMessage(this, MessageBoxUtil::Warning, "警告", QString("Browse 显示:\n工作组：%1 格式不正确!").arg(group), MessageBoxUtil::Ok))
        {

        }
        return;
    } else {
//        ui->comboBox_chainWidth->setCurrentText(iniManager::getGroupType(currGroupId.at(1).toUInt()));
    }
//    ui->comboBox_chainWidth->setCurrentText(m_iniManager->readValue(currentGroup, "type").toString());
    ui->comboBox_chainWidth->setCurrentText(iniManager::getGroupType(currGroupId.at(1).toUInt(), currGroupId.at(2).toUInt()));

    ui->lineEdit_productClass->setText(m_iniManager->readValue(group, "productClass").toString());

    ui->lineEdit_topCameraFoucs->setText(m_iniManager->readValue(group,"topCamFocusVal").toString());
    ui->lineEdit_topCameraLightValue->setText(m_iniManager->readValue(group,"topLightVale").toString());

    ui->lineEdit_sideCameraFoucsA->setText(m_iniManager->readValue(group,"sideCamFocusVal_A").toString());
    ui->lineEdit_sideCameraLightA->setText(m_iniManager->readValue(group,"sideCamLightVal_A").toString());
    ui->lineEdit_sideFillLightA->setText(m_iniManager->readValue(group,"sideFillLightVal_A").toString());

    ui->lineEdit_sideCameraFoucsB->setText(m_iniManager->readValue(group,"sideCamFocusVal_B").toString());
    ui->lineEdit_sideCameraLightB->setText(m_iniManager->readValue(group,"sideCamLightVal_B").toString());
    ui->lineEdit_sideFillLightB->setText(m_iniManager->readValue(group,"sideFillLightVal_B").toString());

    ui->lineEdit_sideCameraFoucsC->setText(m_iniManager->readValue(group,"sideCamFocusVal_C").toString());
    ui->lineEdit_sideCameraLightC->setText(m_iniManager->readValue(group,"sideCamLightVal_C").toString());
    ui->lineEdit_sideFillLightC->setText(m_iniManager->readValue(group,"sideFillLightVal_C").toString());

    ui->lineEdit_sideCameraFoucsD->setText(m_iniManager->readValue(group,"sideCamFocusVal_D").toString());
    ui->lineEdit_sideCameraLightD->setText(m_iniManager->readValue(group,"sideCamLightVal_D").toString());
    ui->lineEdit_sideFillLightD->setText(m_iniManager->readValue(group,"sideFillLightVal_D").toString());
//    ui->hSlider_sideCameraLightValue->setText(m_iniManager->readValue(group,"sideLightVal").toString());
//    ui->hSlider_sideCameraFillLight->setText(m_iniManager->readValue(group,"sideFillLightVal").toString());

    ui->lineEdit_bottomCameraLightValue->setText(m_iniManager->readValue(group,"bottomLightVal").toString());

    m_iniManager->writeValue("current","group", currGroupId.at(0));
}

void Dialog_configWorkGroupParas::on_btn_next_clicked()
{
    if (currentGroupIndex < maxGroupIndex) {
        currentGroupIndex++;
    } else {
        currentGroupIndex = 0; // 循环到第一个组
    }

    currentGroup = groups[currentGroupIndex];
    qDebug() << "Current group:" << currentGroup;

    do_setCurrentGroupBrowse(currentGroup);
}


void Dialog_configWorkGroupParas::on_btn_pre_clicked()
{
    if (currentGroupIndex > 0) {
        currentGroupIndex--;
    } else {
        currentGroupIndex = maxGroupIndex; // 循环到最后一个组
    }
    currentGroup = groups[currentGroupIndex];
    qDebug() << "Current group:" << currentGroup;

    do_setCurrentGroupBrowse(currentGroup);
}

void Dialog_configWorkGroupParas::do_addNewGroup(const uint16_t l, const uint16_t w, const uint16_t h)
{
//    m_newGroup.clear();
////            QString::number(m_iniManager->readValue("current", "count").toInt());

//    m_newGroup << Id << "XXX" << "XXX" << "XXX" << "X";

    m_Id_set = m_iniManager->readValue("current", "count").toString();

    m_L_set = "";
    m_W_set = "";
    m_H_set = "";



//    QString type = iniManager::getGroupType(iniManager::getGroupType(w, l));
    QString type = ui->comboBox_chainWidth->currentText();

//    if(QMessageBox::Yes == MessageBoxUtil::showMessage(this, MessageBoxUtil::Information, "提示",
//                                                         QString("请先配置PLC：\n 配方：%1").arg(m_Id_set)))
//    {
//            return;
//    }


//    if(MessageBoxUtil::Ok == MessageBoxUtil::showMessage(this, MessageBoxUtil::Warning, "警告",
//                                                         QString("产品类型：%1\nL:%2\nW:%3\nH:%4").arg(type).arg(l).arg(w).arg(h),
//                                                         MessageBoxUtil::Ok))
//    {

//    }

//    if(type.isEmpty())
//    {
//        if(MessageBoxUtil::Ok == MessageBoxUtil::showMessage(this, MessageBoxUtil::Warning, "警告", QString("产品类型解析错误，空!").arg(type), MessageBoxUtil::Ok))
//        {

//        }

//    }

    QString name = QString("%1_%2_%3_%4_%5").arg(m_Id_set).arg(m_L_set).arg(m_W_set).arg(m_H_set).arg(type);

    // 初始化，清空
//    ui->lineEdit_L_set->clear();    // 长
//    ui->lineEdit_W_set->clear();    // 宽
//    ui->lineEdit_H_set->clear();    // 高
//    ui->lineEdit_productClass_set->clear(); // 产品类别
    ui->productClassWidget->clear();
    ui->lineEdit_workGroupId_set->clear();  // 工作组编号
//    ui->lineEdit_materialNo_set->clear();   // 物料编号
//    ui->lineEdit_workProcedureSequence_set->clear();// 工作组编号

    int lightInitValue = 100;


//    ui->LineEdit_workGroupName->setText(name);
    ui->lineEdit_workGroupId_set->setText(name);
    ui->comboBox_chainWidth_set->setCurrentText(iniManager::getGroupType(type));

    ui->hSlider_topCameraFoucs->setValue(0);
    ui->hSlider_topCameraLightValue->setValue(lightInitValue);
    ui->hSlider_sideCameraFoucsA->setValue(0);
    ui->hSlider_sideCameraLightA->setValue(lightInitValue);
    ui->hSlider_sideFillLightA->setValue(lightInitValue);
    ui->hSlider_sideCameraFoucsB->setValue(0);
    ui->hSlider_sideCameraLightB->setValue(lightInitValue);
    ui->hSlider_sideFillLightB->setValue(lightInitValue);
    ui->hSlider_sideCameraFoucsC->setValue(0);
    ui->hSlider_sideCameraLightC->setValue(lightInitValue);
    ui->hSlider_sideFillLightC->setValue(lightInitValue);
    ui->hSlider_sideCameraFoucsD->setValue(0);
    ui->hSlider_sideCameraLightD->setValue(lightInitValue);
    ui->hSlider_sideFillLightD->setValue(lightInitValue);
//    ui->hSlider_sideCameraLightValue->setValue(0);
//    ui->hSlider_sideCameraFillLight->setValue(0);
    ui->hSlider_bottomCameraLightValue->setValue(lightInitValue);

//    ui->comboBox_workGroupId->addItem(name);
//    ui->comboBox_workGroupId->setCurrentText(name);




//    QVariantMap newGroupMap;
//    newGroupMap.insert("name", name);
//    newGroupMap.insert("size", size);
//    newGroupMap.insert("type", type);

//    newGroupMap.insert("topCamFocusVal", 0);
//    newGroupMap.insert("topLightVale", 0);
//    newGroupMap.insert("sideCamFocusVal_A", 0);
//    newGroupMap.insert("sideCamFocusVal_B", 0);
//    newGroupMap.insert("sideCamFocusVal_C", 0);
//    newGroupMap.insert("sideCamFocusVal_D", 0);
//    newGroupMap.insert("sideLightVal", 0);
//    newGroupMap.insert("sideFillLightVal", 0);
//    newGroupMap.insert("bottomLightVal", 0);

//    if(m_iniManager->addGroup(Id, newGroupMap))
//    {
//        m_iniManager->writeValue("current", "count", Id.toInt() + 1);

//        m_iniManager->writeValue("current","group", Id);
//        initData();
//    }

    QString sData="0";

    uint8_t val = lightInitValue;
    if(val < 10) sData += "0";
    if(val < 100) sData += "0";
    sData += QString("%1").arg(val);

    QString sDataString = sData;

    sendBottomLightData(QString("SA%1#SB%2#").arg(sDataString).arg(sDataString));
    sendTopRoSideLightData(QString("SA%1#SB%2#SC%3#SD%4#").arg(sDataString).arg(sDataString).arg(sDataString).arg(sDataString));
}

void Dialog_configWorkGroupParas::on_btn_addNewGroup_clicked()
{
    QString Size;// 尺寸大小
    QString ProductClass;// 工件类别
    // 弹出新增工作组编号窗口
    Dialog_newAddGroup *dialog = new Dialog_newAddGroup(this);

    // 创建连接并保存句柄
    auto connection_size = QObject::connect(dialog, &Dialog_newAddGroup::sendSize, [&](QString size){
        Size = size;
    });

    auto connection_productClass = QObject::connect(dialog, &Dialog_newAddGroup::sendProductClass, [&](QString productClass){
        ProductClass = productClass;
    });

    bool flag = (dialog->exec() == QDialog::Accepted);

    // 断开连接
    QObject::disconnect(connection_size);
    QObject::disconnect(connection_productClass);

    if(dialog != nullptr)
    {
        delete dialog;
    }

    // 判断是否点击确认
    if(true != flag )
    {

        return;
    }




    // 获取新增编号
    m_Id_set = m_iniManager->readValue("current", "count").toString();


    if(QMessageBox::Ok == MessageBoxUtil::hintMessage(this, MessageBoxUtil::Information, "新增成功",
                                                         QString("新增配方：%1").arg(m_Id_set)))
    {
        m_newGroupFlag = true;
        ui->productClassWidget->setEnabled(true);

        do_addNewGroup(220,220,220);

        ui->productSizeWidget->setSize(Size);
        ui->productClassWidget->setProductClass(ProductClass);

        ui->stackedWidget->setCurrentIndex(1);
    }

}

void Dialog_configWorkGroupParas::on_comboBox_workGroupId_currentTextChanged(const QString &arg1)
{
    QStringList currGroupId = iniManager::splitString(arg1);
    if(currGroupId.isEmpty())
    {
        qDebug() << "工作组编号，拆分错误";
//        if(MessageBoxUtil::Ok == MessageBoxUtil::showMessage(this, MessageBoxUtil::Warning, "警告", QString("currentTextChanged 显示:\n工作组：%1 格式不正确!").arg(arg1), MessageBoxUtil::Ok))
        {

        }
        return;
    }

    do_setCurrentGroupBrowse(currGroupId.at(0));
}

void Dialog_configWorkGroupParas::on_btn_toSave_clicked()
{
    m_newGroupFlag = false;
    ui->stackedWidget->setCurrentIndex(1);
    QStringList currGroupId = iniManager::splitString(ui->comboBox_workGroupId->currentText());
    do_setCurrentGroupShow(currGroupId.at(0));
}

void Dialog_configWorkGroupParas::on_btn_exit_clicked()
{
    reject();
}


void Dialog_configWorkGroupParas::do_setTopCameraFoucs(int val)
{
    ui->hSlider_topCameraFoucs->setValue(val);
}

void Dialog_configWorkGroupParas::do_initTopFocus(int angle = 300)
{
    sendTopAdjustData(formSetAngleData(1480));
    Dialog_camAdjust::topCamadjustValue = 740;

    // 延时等待3s
    waitForTime(3);

    // 设置默认值
    int setAngle = angle;

    int topVal = -(Dialog_camAdjust::topCamadjustValue - setAngle);// 顶部

    sendTopAdjustData(formSetAngleData(topVal));
    Dialog_camAdjust::topCamadjustValue = setAngle;

    // 延时等待1s
    waitForTime(1);
}

void Dialog_configWorkGroupParas::do_initSideFocus(int angle = 300)
{
    sendSideAdjustData(formSetAngleData(1480));
    Dialog_camAdjust::sideCamadjustValue = 740;

    // 延时等待3s
    waitForTime(3);

    // 设置默认值
    int setAngle = angle;

    int topVal = -(Dialog_camAdjust::sideCamadjustValue - setAngle);// 侧面

    sendSideAdjustData(formSetAngleData(topVal));
    Dialog_camAdjust::sideCamadjustValue = setAngle;

    // 延时等待1s
    waitForTime(1);
}

void Dialog_configWorkGroupParas::on_btn_getTopCameraFoucs_clicked()
{
    ui->btn_getTopCameraFoucs->setEnabled(false);

    // 获取当前拖动调值
    int angle = ui->hSlider_topCameraFoucs->value();

    // 初始化顶部焦距
    do_initTopFocus(angle);

    Dialog_camAdjust *dialog = new Dialog_camAdjust(this, Dialog_camAdjust::Top);

    connect(dialog,&Dialog_camAdjust::sendTopAdjustData,this, &Dialog_configWorkGroupParas::sendTopAdjustData);
    connect(dialog,&Dialog_camAdjust::sendSideAdjustData,this, &Dialog_configWorkGroupParas::sendSideAdjustData);
    connect(this, &Dialog_configWorkGroupParas::getTopAdjustRecv, dialog, &Dialog_camAdjust::getTopRecv);
    connect(this, &Dialog_configWorkGroupParas::getSideAdjustRecv, dialog, &Dialog_camAdjust::getSideRecv);

    connect(dialog, &Dialog_camAdjust::returnData, this, &Dialog_configWorkGroupParas::do_setTopCameraFoucs);
    dialog->exec();
    disconnect(dialog, &Dialog_camAdjust::returnData, this, &Dialog_configWorkGroupParas::do_setTopCameraFoucs);

    disconnect(dialog,&Dialog_camAdjust::sendTopAdjustData,this, &Dialog_configWorkGroupParas::sendTopAdjustData);
    disconnect(dialog,&Dialog_camAdjust::sendSideAdjustData,this, &Dialog_configWorkGroupParas::sendSideAdjustData);
    disconnect(this, &Dialog_configWorkGroupParas::getTopAdjustRecv, dialog, &Dialog_camAdjust::getTopRecv);
    disconnect(this, &Dialog_configWorkGroupParas::getSideAdjustRecv, dialog, &Dialog_camAdjust::getSideRecv);

    if(dialog != nullptr)
        delete dialog;

    ui->btn_getTopCameraFoucs->setEnabled(true);
}

void Dialog_configWorkGroupParas::do_setTopCameraLightValue(int val)
{
    ui->hSlider_topCameraLightValue->setValue(val);
}

void Dialog_configWorkGroupParas::on_btn_getTopCameraLightValue_clicked()
{

    // 顶部光源
    QString sideLight_C = Dialog_LightControl::getSetLightsDataString("A", ui->hSlider_topCameraLightValue->value());
    QString sideLight_D = Dialog_LightControl::getSetLightsDataString("B", ui->hSlider_topCameraLightValue->value());
    emit sendTopRoSideLightData(sideLight_C+sideLight_D);
}

void Dialog_configWorkGroupParas::do_setSideCameraFoucsA(int val)
{
    ui->hSlider_sideCameraFoucsA->setValue(val);
}

void Dialog_configWorkGroupParas::on_btn_getSideCameraFoucsA_clicked()
{
    ui->btn_getSideCameraFoucsA->setEnabled(false);

//    sendSideAdjustData(formSetAngleData(1480));
//    Dialog_camAdjust::sideCamadjustValue = 740;

//    // 延时等待2s
//    waitForTime(2);

    // 获取当前拖动调值
    int angle = ui->hSlider_sideCameraFoucsA->value();

    // 初始化侧面焦距
    do_initSideFocus(angle);

    Dialog_camAdjust *dialog = new Dialog_camAdjust(this, Dialog_camAdjust::Side);

    connect(dialog,&Dialog_camAdjust::sendTopAdjustData,this, &Dialog_configWorkGroupParas::sendTopAdjustData);
    connect(dialog,&Dialog_camAdjust::sendSideAdjustData,this, &Dialog_configWorkGroupParas::sendSideAdjustData);
    connect(this, &Dialog_configWorkGroupParas::getTopAdjustRecv, dialog, &Dialog_camAdjust::getTopRecv);
    connect(this, &Dialog_configWorkGroupParas::getSideAdjustRecv, dialog, &Dialog_camAdjust::getSideRecv);

    connect(dialog, &Dialog_camAdjust::returnData, this, &Dialog_configWorkGroupParas::do_setSideCameraFoucsA);
    dialog->exec();
    disconnect(dialog, &Dialog_camAdjust::returnData, this, &Dialog_configWorkGroupParas::do_setSideCameraFoucsA);

    disconnect(dialog,&Dialog_camAdjust::sendTopAdjustData,this, &Dialog_configWorkGroupParas::sendTopAdjustData);
    disconnect(dialog,&Dialog_camAdjust::sendSideAdjustData,this, &Dialog_configWorkGroupParas::sendSideAdjustData);
    disconnect(this, &Dialog_configWorkGroupParas::getTopAdjustRecv, dialog, &Dialog_camAdjust::getTopRecv);
    disconnect(this, &Dialog_configWorkGroupParas::getSideAdjustRecv, dialog, &Dialog_camAdjust::getSideRecv);

    if(dialog != nullptr)
        delete dialog;

    ui->btn_getSideCameraFoucsA->setEnabled(true);
}


void Dialog_configWorkGroupParas::do_setSideCameraLightA(int val)
{
    ui->hSlider_sideCameraLightA->setValue(val);
}


void Dialog_configWorkGroupParas::on_btn_getSideCameraLightA_clicked()
{
    // 侧面光源 A
    QString sideLight_C = Dialog_LightControl::getSetLightsDataString("C", ui->hSlider_sideCameraLightA->value());
    QString sideLight_D = Dialog_LightControl::getSetLightsDataString("D", ui->hSlider_sideCameraLightA->value());
    emit sendTopRoSideLightData(sideLight_C+sideLight_D);
}

void Dialog_configWorkGroupParas::do_setSideFillLightA(int val)
{
    ui->hSlider_sideFillLightA->setValue(val);
}

void Dialog_configWorkGroupParas::on_btn_getSideFillLightA_clicked()
{

    // 侧面补光 A
    QString FillLight = Dialog_LightControl::getSetLightsDataString("B", ui->hSlider_sideFillLightA->value());
    emit sendBottomLightData(FillLight);
}



void Dialog_configWorkGroupParas::do_setSideCameraFoucsB(int val)
{
    ui->hSlider_sideCameraFoucsB->setValue(val);
}

void Dialog_configWorkGroupParas::on_btn_getSideCameraFoucsB_clicked()
{
    ui->btn_getSideCameraFoucsB->setEnabled(false);

//    sendSideAdjustData(formSetAngleData(1480));
//    Dialog_camAdjust::sideCamadjustValue = 740;

//    // 延时等待2s
//    waitForTime(2);

    // 获取当前拖动调值
    int angle = ui->hSlider_sideCameraFoucsB->value();

    // 初始化侧面焦距
    do_initSideFocus(angle);

    Dialog_camAdjust *dialog = new Dialog_camAdjust(this, Dialog_camAdjust::Side);

    connect(dialog,&Dialog_camAdjust::sendTopAdjustData,this, &Dialog_configWorkGroupParas::sendTopAdjustData);
    connect(dialog,&Dialog_camAdjust::sendSideAdjustData,this, &Dialog_configWorkGroupParas::sendSideAdjustData);
    connect(this, &Dialog_configWorkGroupParas::getTopAdjustRecv, dialog, &Dialog_camAdjust::getTopRecv);
    connect(this, &Dialog_configWorkGroupParas::getSideAdjustRecv, dialog, &Dialog_camAdjust::getSideRecv);

    connect(dialog, &Dialog_camAdjust::returnData, this, &Dialog_configWorkGroupParas::do_setSideCameraFoucsB);
    dialog->exec();
    disconnect(dialog, &Dialog_camAdjust::returnData, this, &Dialog_configWorkGroupParas::do_setSideCameraFoucsB);

    disconnect(dialog,&Dialog_camAdjust::sendTopAdjustData,this, &Dialog_configWorkGroupParas::sendTopAdjustData);
    disconnect(dialog,&Dialog_camAdjust::sendSideAdjustData,this, &Dialog_configWorkGroupParas::sendSideAdjustData);
    disconnect(this, &Dialog_configWorkGroupParas::getTopAdjustRecv, dialog, &Dialog_camAdjust::getTopRecv);
    disconnect(this, &Dialog_configWorkGroupParas::getSideAdjustRecv, dialog, &Dialog_camAdjust::getSideRecv);

    if(dialog != nullptr)
        delete dialog;

    ui->btn_getSideCameraFoucsB->setEnabled(true);
}


void Dialog_configWorkGroupParas::do_setSideCameraLightB(int val)
{
    ui->hSlider_sideCameraLightB->setValue(val);
}


void Dialog_configWorkGroupParas::on_btn_getSideCameraLightB_clicked()
{
//    Dialog_LightControl *dialog = new Dialog_LightControl(this, Dialog_LightControl::Side);

//    connect(dialog, &Dialog_LightControl::sendTopRoSideLightAdjustData,this, &Dialog_configWorkGroupParas::sendTopRoSideLightData);
//    connect(dialog, &Dialog_LightControl::sendBottomLightAdjustData,this, &Dialog_configWorkGroupParas::sendBottomLightData);
//    connect(this, &Dialog_configWorkGroupParas::getTopLightRecv, dialog, &Dialog_LightControl::getRecv);
//    connect(this, &Dialog_configWorkGroupParas::getBottomLightRecv,dialog, &Dialog_LightControl::getRecv);

//    sendTopRoSideLightData("SC#SD#");
//    connect(dialog, &Dialog_LightControl::returnData, this, &Dialog_configWorkGroupParas::do_setSideCameraLightB);
//    dialog->exec();
//    disconnect(dialog, &Dialog_LightControl::returnData, this, &Dialog_configWorkGroupParas::do_setSideCameraLightB);

//    disconnect(dialog, &Dialog_LightControl::sendTopRoSideLightAdjustData,this, &Dialog_configWorkGroupParas::sendTopRoSideLightData);
//    disconnect(dialog, &Dialog_LightControl::sendBottomLightAdjustData,this, &Dialog_configWorkGroupParas::sendBottomLightData);
//    disconnect(this, &Dialog_configWorkGroupParas::getTopLightRecv,dialog, &Dialog_LightControl::getRecv);
//    disconnect(this, &Dialog_configWorkGroupParas::getBottomLightRecv,dialog, &Dialog_LightControl::getRecv);

//    if(dialog != nullptr)
//    {
//        delete dialog;
//    }

    // 侧面光源 B
    QString sideLight_C = Dialog_LightControl::getSetLightsDataString("C", ui->hSlider_sideCameraLightB->value());
    QString sideLight_D = Dialog_LightControl::getSetLightsDataString("D", ui->hSlider_sideCameraLightB->value());
    emit sendTopRoSideLightData(sideLight_C+sideLight_D);
}

void Dialog_configWorkGroupParas::do_setSideFillLightB(int val)
{
    ui->hSlider_sideFillLightB->setValue(val);
}

void Dialog_configWorkGroupParas::on_btn_getSideFillLightB_clicked()
{
//    Dialog_LightControl *dialog = new Dialog_LightControl(this, Dialog_LightControl::Fill);

//    connect(dialog, &Dialog_LightControl::sendTopRoSideLightAdjustData,this, &Dialog_configWorkGroupParas::sendTopRoSideLightData);
//    connect(dialog, &Dialog_LightControl::sendBottomLightAdjustData,this, &Dialog_configWorkGroupParas::sendBottomLightData);
//    connect(this, &Dialog_configWorkGroupParas::getTopLightRecv, dialog, &Dialog_LightControl::getRecv);
//    connect(this, &Dialog_configWorkGroupParas::getBottomLightRecv,dialog, &Dialog_LightControl::getRecv);

//    sendTopRoSideLightData("SB#");
//    connect(dialog, &Dialog_LightControl::returnData, this, &Dialog_configWorkGroupParas::do_setSideFillLightB);
//    dialog->exec();
//    disconnect(dialog, &Dialog_LightControl::returnData, this, &Dialog_configWorkGroupParas::do_setSideFillLightB);

//    disconnect(dialog, &Dialog_LightControl::sendTopRoSideLightAdjustData,this, &Dialog_configWorkGroupParas::sendTopRoSideLightData);
//    disconnect(dialog, &Dialog_LightControl::sendBottomLightAdjustData,this, &Dialog_configWorkGroupParas::sendBottomLightData);
//    disconnect(this, &Dialog_configWorkGroupParas::getTopLightRecv,dialog, &Dialog_LightControl::getRecv);
//    disconnect(this, &Dialog_configWorkGroupParas::getBottomLightRecv,dialog, &Dialog_LightControl::getRecv);

//    if(dialog != nullptr)
//    {
//        delete dialog;
//    }
    // 侧面补光 C
    QString FillLight = Dialog_LightControl::getSetLightsDataString("B", ui->hSlider_sideFillLightB->value());
    emit sendBottomLightData(FillLight);
}




void Dialog_configWorkGroupParas::do_setSideCameraFoucsC(int val)
{
    ui->hSlider_sideCameraFoucsC->setValue(val);
}

void Dialog_configWorkGroupParas::on_btn_getSideCameraFoucsC_clicked()
{
    ui->btn_getSideCameraFoucsC->setEnabled(false);

//    sendSideAdjustData(formSetAngleData(1480));
//    Dialog_camAdjust::sideCamadjustValue = 740;

//    // 延时等待2s
//    waitForTime(2);

    // 获取当前拖动调值
    int angle = ui->hSlider_sideCameraFoucsC->value();

    // 初始化侧面焦距
    do_initSideFocus(angle);

    Dialog_camAdjust *dialog = new Dialog_camAdjust(this, Dialog_camAdjust::Side);

    connect(dialog,&Dialog_camAdjust::sendTopAdjustData,this, &Dialog_configWorkGroupParas::sendTopAdjustData);
    connect(dialog,&Dialog_camAdjust::sendSideAdjustData,this, &Dialog_configWorkGroupParas::sendSideAdjustData);
    connect(this, &Dialog_configWorkGroupParas::getTopAdjustRecv, dialog, &Dialog_camAdjust::getTopRecv);
    connect(this, &Dialog_configWorkGroupParas::getSideAdjustRecv, dialog, &Dialog_camAdjust::getSideRecv);

    connect(dialog, &Dialog_camAdjust::returnData, this, &Dialog_configWorkGroupParas::do_setSideCameraFoucsC);
    dialog->exec();
    disconnect(dialog, &Dialog_camAdjust::returnData, this, &Dialog_configWorkGroupParas::do_setSideCameraFoucsC);

    disconnect(dialog,&Dialog_camAdjust::sendTopAdjustData,this, &Dialog_configWorkGroupParas::sendTopAdjustData);
    disconnect(dialog,&Dialog_camAdjust::sendSideAdjustData,this, &Dialog_configWorkGroupParas::sendSideAdjustData);
    disconnect(this, &Dialog_configWorkGroupParas::getTopAdjustRecv, dialog, &Dialog_camAdjust::getTopRecv);
    disconnect(this, &Dialog_configWorkGroupParas::getSideAdjustRecv, dialog, &Dialog_camAdjust::getSideRecv);

    if(dialog != nullptr)
        delete dialog;

    ui->btn_getSideCameraFoucsC->setEnabled(true);
}


void Dialog_configWorkGroupParas::do_setSideCameraLightC(int val)
{
    ui->hSlider_sideCameraLightC->setValue(val);
}


void Dialog_configWorkGroupParas::on_btn_getSideCameraLightC_clicked()
{
//    Dialog_LightControl *dialog = new Dialog_LightControl(this, Dialog_LightControl::Side);

//    connect(dialog, &Dialog_LightControl::sendTopRoSideLightAdjustData,this, &Dialog_configWorkGroupParas::sendTopRoSideLightData);
//    connect(dialog, &Dialog_LightControl::sendBottomLightAdjustData,this, &Dialog_configWorkGroupParas::sendBottomLightData);
//    connect(this, &Dialog_configWorkGroupParas::getTopLightRecv, dialog, &Dialog_LightControl::getRecv);
//    connect(this, &Dialog_configWorkGroupParas::getBottomLightRecv,dialog, &Dialog_LightControl::getRecv);

//    sendTopRoSideLightData("SC#SD#");
//    connect(dialog, &Dialog_LightControl::returnData, this, &Dialog_configWorkGroupParas::do_setSideCameraLightC);
//    dialog->exec();
//    disconnect(dialog, &Dialog_LightControl::returnData, this, &Dialog_configWorkGroupParas::do_setSideCameraLightC);

//    disconnect(dialog, &Dialog_LightControl::sendTopRoSideLightAdjustData,this, &Dialog_configWorkGroupParas::sendTopRoSideLightData);
//    disconnect(dialog, &Dialog_LightControl::sendBottomLightAdjustData,this, &Dialog_configWorkGroupParas::sendBottomLightData);
//    disconnect(this, &Dialog_configWorkGroupParas::getTopLightRecv,dialog, &Dialog_LightControl::getRecv);
//    disconnect(this, &Dialog_configWorkGroupParas::getBottomLightRecv,dialog, &Dialog_LightControl::getRecv);

//    if(dialog != nullptr)
//    {
//        delete dialog;
//    }
    // 侧面光源 C
    QString sideLight_C = Dialog_LightControl::getSetLightsDataString("C", ui->hSlider_sideCameraLightC->value());
    QString sideLight_D = Dialog_LightControl::getSetLightsDataString("D", ui->hSlider_sideCameraLightC->value());
    emit sendTopRoSideLightData(sideLight_C+sideLight_D);
}

void Dialog_configWorkGroupParas::do_setSideFillLightC(int val)
{
    ui->hSlider_sideFillLightC->setValue(val);
}

void Dialog_configWorkGroupParas::on_btn_getSideFillLightC_clicked()
{
//    Dialog_LightControl *dialog = new Dialog_LightControl(this, Dialog_LightControl::Fill);

//    connect(dialog, &Dialog_LightControl::sendTopRoSideLightAdjustData,this, &Dialog_configWorkGroupParas::sendTopRoSideLightData);
//    connect(dialog, &Dialog_LightControl::sendBottomLightAdjustData,this, &Dialog_configWorkGroupParas::sendBottomLightData);
//    connect(this, &Dialog_configWorkGroupParas::getTopLightRecv, dialog, &Dialog_LightControl::getRecv);
//    connect(this, &Dialog_configWorkGroupParas::getBottomLightRecv,dialog, &Dialog_LightControl::getRecv);

//    sendTopRoSideLightData("SB#");
//    connect(dialog, &Dialog_LightControl::returnData, this, &Dialog_configWorkGroupParas::do_setSideFillLightC);
//    dialog->exec();
//    disconnect(dialog, &Dialog_LightControl::returnData, this, &Dialog_configWorkGroupParas::do_setSideFillLightC);

//    disconnect(dialog, &Dialog_LightControl::sendTopRoSideLightAdjustData,this, &Dialog_configWorkGroupParas::sendTopRoSideLightData);
//    disconnect(dialog, &Dialog_LightControl::sendBottomLightAdjustData,this, &Dialog_configWorkGroupParas::sendBottomLightData);
//    disconnect(this, &Dialog_configWorkGroupParas::getTopLightRecv,dialog, &Dialog_LightControl::getRecv);
//    disconnect(this, &Dialog_configWorkGroupParas::getBottomLightRecv,dialog, &Dialog_LightControl::getRecv);

//    if(dialog != nullptr)
//    {
//        delete dialog;
//    }
    // 侧面补光 C
    QString FillLight = Dialog_LightControl::getSetLightsDataString("B", ui->hSlider_sideFillLightC->value());
    emit sendBottomLightData(FillLight);
}



void Dialog_configWorkGroupParas::do_setSideCameraFoucsD(int val)
{
    ui->hSlider_sideCameraFoucsD->setValue(val);
}

void Dialog_configWorkGroupParas::on_btn_getSideCameraFoucsD_clicked()
{
    ui->btn_getSideCameraFoucsD->setEnabled(false);

//    sendSideAdjustData(formSetAngleData(1480));
//    Dialog_camAdjust::sideCamadjustValue = 740;

//    // 延时等待2s
//    waitForTime(2);

    // 获取当前拖动调值
    int angle = ui->hSlider_sideCameraFoucsD->value();

    // 初始化侧面焦距
    do_initSideFocus(angle);

    Dialog_camAdjust *dialog = new Dialog_camAdjust(this, Dialog_camAdjust::Side);

    connect(dialog,&Dialog_camAdjust::sendTopAdjustData,this, &Dialog_configWorkGroupParas::sendTopAdjustData);
    connect(dialog,&Dialog_camAdjust::sendSideAdjustData,this, &Dialog_configWorkGroupParas::sendSideAdjustData);
    connect(this, &Dialog_configWorkGroupParas::getTopAdjustRecv, dialog, &Dialog_camAdjust::getTopRecv);
    connect(this, &Dialog_configWorkGroupParas::getSideAdjustRecv, dialog, &Dialog_camAdjust::getSideRecv);

    connect(dialog, &Dialog_camAdjust::returnData, this, &Dialog_configWorkGroupParas::do_setSideCameraFoucsD);
    dialog->exec();
    disconnect(dialog, &Dialog_camAdjust::returnData, this, &Dialog_configWorkGroupParas::do_setSideCameraFoucsD);

    disconnect(dialog,&Dialog_camAdjust::sendTopAdjustData,this, &Dialog_configWorkGroupParas::sendTopAdjustData);
    disconnect(dialog,&Dialog_camAdjust::sendSideAdjustData,this, &Dialog_configWorkGroupParas::sendSideAdjustData);
    disconnect(this, &Dialog_configWorkGroupParas::getTopAdjustRecv, dialog, &Dialog_camAdjust::getTopRecv);
    disconnect(this, &Dialog_configWorkGroupParas::getSideAdjustRecv, dialog, &Dialog_camAdjust::getSideRecv);

    if(dialog != nullptr)
        delete dialog;

    ui->btn_getSideCameraFoucsD->setEnabled(true);
}


void Dialog_configWorkGroupParas::do_setSideCameraLightD(int val)
{
    ui->hSlider_sideCameraLightD->setValue(val);
}


void Dialog_configWorkGroupParas::on_btn_getSideCameraLightD_clicked()
{
//    Dialog_LightControl *dialog = new Dialog_LightControl(this, Dialog_LightControl::Side);

//    connect(dialog, &Dialog_LightControl::sendTopRoSideLightAdjustData,this, &Dialog_configWorkGroupParas::sendTopRoSideLightData);
//    connect(dialog, &Dialog_LightControl::sendBottomLightAdjustData,this, &Dialog_configWorkGroupParas::sendBottomLightData);
//    connect(this, &Dialog_configWorkGroupParas::getTopLightRecv, dialog, &Dialog_LightControl::getRecv);
//    connect(this, &Dialog_configWorkGroupParas::getBottomLightRecv,dialog, &Dialog_LightControl::getRecv);

//    sendTopRoSideLightData("SC#SD#");
//    connect(dialog, &Dialog_LightControl::returnData, this, &Dialog_configWorkGroupParas::do_setSideCameraLightD);
//    dialog->exec();
//    disconnect(dialog, &Dialog_LightControl::returnData, this, &Dialog_configWorkGroupParas::do_setSideCameraLightD);

//    disconnect(dialog, &Dialog_LightControl::sendTopRoSideLightAdjustData,this, &Dialog_configWorkGroupParas::sendTopRoSideLightData);
//    disconnect(dialog, &Dialog_LightControl::sendBottomLightAdjustData,this, &Dialog_configWorkGroupParas::sendBottomLightData);
//    disconnect(this, &Dialog_configWorkGroupParas::getTopLightRecv,dialog, &Dialog_LightControl::getRecv);
//    disconnect(this, &Dialog_configWorkGroupParas::getBottomLightRecv,dialog, &Dialog_LightControl::getRecv);

//    if(dialog != nullptr)
//    {
//        delete dialog;
//    }
    // 侧面光源 D
    QString sideLight_C = Dialog_LightControl::getSetLightsDataString("C", ui->hSlider_sideCameraLightD->value());
    QString sideLight_D = Dialog_LightControl::getSetLightsDataString("D", ui->hSlider_sideCameraLightD->value());
    emit sendTopRoSideLightData(sideLight_C+sideLight_D);
}

void Dialog_configWorkGroupParas::do_setSideFillLightD(int val)
{
    ui->hSlider_sideFillLightD->setValue(val);
}

void Dialog_configWorkGroupParas::on_btn_getSideFillLightD_clicked()
{
//    Dialog_LightControl *dialog = new Dialog_LightControl(this, Dialog_LightControl::Fill);

//    connect(dialog, &Dialog_LightControl::sendTopRoSideLightAdjustData,this, &Dialog_configWorkGroupParas::emit sendTopRoSideLightData);
//    connect(dialog, &Dialog_LightControl::sendBottomLightAdjustData,this, &Dialog_configWorkGroupParas::sendBottomLightData);
//    connect(this, &Dialog_configWorkGroupParas::getTopLightRecv, dialog, &Dialog_LightControl::getRecv);
//    connect(this, &Dialog_configWorkGroupParas::getBottomLightRecv,dialog, &Dialog_LightControl::getRecv);

//    sendTopRoSideLightData("SB#");
//    connect(dialog, &Dialog_LightControl::returnData, this, &Dialog_configWorkGroupParas::do_setSideFillLightD);
//    dialog->exec();
//    disconnect(dialog, &Dialog_LightControl::returnData, this, &Dialog_configWorkGroupParas::do_setSideFillLightD);

//    disconnect(dialog, &Dialog_LightControl::sendTopRoSideLightAdjustData,this, &Dialog_configWorkGroupParas::sendTopRoSideLightData);
//    disconnect(dialog, &Dialog_LightControl::sendBottomLightAdjustData,this, &Dialog_configWorkGroupParas::sendBottomLightData);
//    disconnect(this, &Dialog_configWorkGroupParas::getTopLightRecv,dialog, &Dialog_LightControl::getRecv);
//    disconnect(this, &Dialog_configWorkGroupParas::getBottomLightRecv,dialog, &Dialog_LightControl::getRecv);

//    if(dialog != nullptr)
//    {
//        delete dialog;
//    }

    // 侧面补光 D
    QString FillLight = Dialog_LightControl::getSetLightsDataString("B", ui->hSlider_sideFillLightD->value());
    emit sendBottomLightData(FillLight);
}

void Dialog_configWorkGroupParas::do_setBottomCameraLightValue(int val)
{
    ui->hSlider_bottomCameraLightValue->setValue(val);
}

void Dialog_configWorkGroupParas::on_btn_getBottomCameraLightValue_clicked()
{
//    Dialog_LightControl *dialog = new Dialog_LightControl(this, Dialog_LightControl::Bottom);

//    connect(dialog, &Dialog_LightControl::sendTopRoSideLightAdjustData,this, &Dialog_configWorkGroupParas::sendTopRoSideLightData);
//    connect(dialog, &Dialog_LightControl::sendBottomLightAdjustData,this, &Dialog_configWorkGroupParas::sendBottomLightData);
//    connect(this, &Dialog_configWorkGroupParas::getTopLightRecv, dialog, &Dialog_LightControl::getRecv);
//    connect(this, &Dialog_configWorkGroupParas::getBottomLightRecv,dialog, &Dialog_LightControl::getRecv);

//    sendTopRoSideLightData("SA#");
//    connect(dialog, &Dialog_LightControl::returnData, this, &Dialog_configWorkGroupParas::do_setBottomCameraLightValue);
//    dialog->exec();
//    disconnect(dialog, &Dialog_LightControl::returnData, this, &Dialog_configWorkGroupParas::do_setBottomCameraLightValue);

//    disconnect(dialog, &Dialog_LightControl::sendTopRoSideLightAdjustData,this, &Dialog_configWorkGroupParas::sendTopRoSideLightData);
//    disconnect(dialog, &Dialog_LightControl::sendBottomLightAdjustData,this, &Dialog_configWorkGroupParas::sendBottomLightData);
//    disconnect(this, &Dialog_configWorkGroupParas::getTopLightRecv,dialog, &Dialog_LightControl::getRecv);
//    disconnect(this, &Dialog_configWorkGroupParas::getBottomLightRecv,dialog, &Dialog_LightControl::getRecv);

//    if(dialog != nullptr)
//    {
//        delete dialog;
//    }

    // 底部光源
    QString bottomLight = Dialog_LightControl::getSetLightsDataString("A", ui->hSlider_bottomCameraLightValue->value());
    emit sendBottomLightData(bottomLight);

}

void Dialog_configWorkGroupParas::do_getProductClassNewGroup(QString productClass)
{

    on_btn_addNewGroup_clicked();
//    ui->lineEdit_productClass_set->setText(productClass);
//    ui->lineEdit_productClass_set->setEnabled(false);

    ui->productClassWidget->setProductClass(productClass);
    ui->productClassWidget->setEnabled(false);

}

void Dialog_configWorkGroupParas::on_stackedWidget_currentChanged(int arg1)
{
    if(arg1 == 0)
    {
        this->setWindowTitle("工作组配置浏览");
    }
    else if(arg1 == 1)
    {
        this->setWindowTitle("工作组参数配置");
    }
}



void Dialog_configWorkGroupParas::waitForTime(int finishTime, int intervalTime)
{
    // 延时等待并检查 PLC 是否复位完成
    QEventLoop loop;
    QTimer timer;
    timer.setInterval(intervalTime); // 设置检查间隔，例如每秒检查一次

    connect(&timer, &QTimer::timeout, [&]()
    {
        static int count = 0;
        // 检查 PLC 是否复位完成
        if (++count >= finishTime) // 假设这是一个检查 PLC 状态的函数
        {
            loop.quit(); // 退出事件循环
        }
        qDebug() << "conut:" << count;
        count %= finishTime;
    });

    timer.start();
    loop.exec(); // 进入事件循环，等待 PLC 复位完成
}

QByteArray Dialog_configWorkGroupParas::intToByteArray(int value)
{
    QByteArray byteArray;
    byteArray.resize(4);

    byteArray[0] = (uint8_t)(value >> 24) & 0xFF;
    byteArray[1] = (uint8_t)(value >> 16) & 0xFF;
    byteArray[2] = (uint8_t)(value >> 8) & 0xFF;
    byteArray[3] = (uint8_t) value & 0xFF;

    return byteArray;
}

QByteArray Dialog_configWorkGroupParas::formSetAngleData(int angle)
{
    QByteArray dat;
    dat.append(0x01);
    dat.append(0x64);
    dat.append(0x01);
    int temp = 100 * 16384 /6000;
    dat+=intToByteArray(temp);
    temp = angle * 16384 /360;
    dat+=intToByteArray(temp);

    dat.append('\x00');
    dat.append('\x00');
    dat.append('\x00');

    return dat;
}

